//
//  LMESchemePageModel.m
//  WelfareManager
//
//  Created by longmin on 17/2/28.
//  Copyright © 2017年 timtian. All rights reserved.
//

#import "LMESchemePageModel.h"

@implementation LMESchemePageModel

#pragma mark - 生命周期

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.sort = 1;
//        self.detailObject = [[LMEPageDetailModel alloc] init];
    }
    return self;
}

#pragma mark - Public 

+ (NSMutableArray *)pageArrayWithGoodsList:(NSArray <LMEGoodsModel *> *)goodsList {
    NSMutableArray *pageList = [NSMutableArray array];
    for (LMEGoodsModel *goodsModel in goodsList) {
        LMESchemePageModel *pageModel = [[self alloc] initWithGoods:goodsModel];
        [pageList addObject:pageModel];
    }
    return pageList;
}

- (instancetype)initWithGoods:(LMEGoodsModel *)goodsModel {
    
    if (self = [self init]) {
        self.type = LMEPageTypeGoods;
        self.product_id = goodsModel.product_id;
//        self.detail = [LMEPageDetailModel pageDetailWithGoodsModel:goodsModel];
//        self.detailObject = goodsModel;
        self.detailObject = [LMEPageDetailModel pageDetailWithGoodsModel:goodsModel];
    }
    return self;
}

#pragma mark - MJExtention
/** 字典转模型和模型转字典时忽略的属性名 */
+ (NSArray *)mj_ignoredPropertyNames {
    return @[@"clipImage",@"detailObject"];
}

/**
 字典转模型完毕
 */
- (void)mj_keyValuesDidFinishConvertingToObject {
    NSLog(@"字典转模型完毕");
    
    NSDictionary *jsonDict = [self.detail mj_JSONObject];
    
    self.detailObject = [LMEPageDetailModel mj_objectWithKeyValues:jsonDict];
}

/**
 模型转字典开始 
 */
- (void)lm_objectWillStartConvertToKeyValues {
    NSLog(@"模型转字典即将开始");
    self.detail = [[self.detailObject mj_JSONString] stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
}

#pragma mark - NSObject
- (NSString *)description {
    return [NSString stringWithFormat:@"{\n\ttype: %u\n\tdetail: %@\n\tsort: %ld\n}",self.type,self.detail,self.sort];
}

@end
